home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / acosh.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  3KB  |  109 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                              N O T I C E                             *
  4.  *                                                                      *
  5.  *                      Copyright Abandoned, 1987, Fred Fish            *
  6.  *                                                                      *
  7.  *      This previously copyrighted work has been placed into the       *
  8.  *      public domain by the author (Fred Fish) and may be freely used  *
  9.  *      for any purpose, private or commercial.  I would appreciate     *
  10.  *      it, as a courtesy, if this notice is left in all copies and     *
  11.  *      derivative works.  Thank you, and enjoy...                      *
  12.  *                                                                      *
  13.  *      The author makes no warranty of any kind with respect to this   *
  14.  *      product and explicitly disclaims any implied warranties of      *
  15.  *      merchantability or fitness for any particular purpose.          *
  16.  *                                                                      *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *      acosh   double precision hyperbolic arc cosine
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *      acosh
  28.  *      machine independent routines
  29.  *      math libraries
  30.  *
  31.  *  DESCRIPTION
  32.  *
  33.  *      Returns double precision hyperbolic arc cosine of double precision
  34.  *      floating point number.
  35.  *
  36.  *  USAGE
  37.  *
  38.  *      double acosh (x)
  39.  *      double x;
  40.  *
  41.  *  RESTRICTIONS
  42.  *
  43.  *      The range of the ACOSH function is all real numbers greater
  44.  *      than or equal to 1.0 however large arguments may cause
  45.  *      overflow in the x squared portion of the function evaluation.
  46.  *
  47.  *      For precision information refer to documentation of the
  48.  *      floating point library primatives called.
  49.  *      
  50.  *  PROGRAMMER
  51.  *
  52.  *      Fred Fish
  53.  *
  54.  *  INTERNALS
  55.  *
  56.  *      Computes acosh(x) from:
  57.  *
  58.  *              1.      If x < 1.0 then report illegal
  59.  *                      argument and return zero.
  60.  *
  61.  *              2.      If x > sqrt(MAXDOUBLE) then
  62.  *                      set x = sqrt(MAXDOUBLE and
  63.  *                      continue after reporting overflow.
  64.  *
  65.  *              3.      acosh(x) = log [x+sqrt(x**2 - 1)]
  66.  *
  67.  */
  68.  
  69. #include <stdio.h>
  70. #include "pml.h"
  71.  
  72. static char funcname[] = "acosh";
  73.  
  74. double acosh (x)
  75. double x;
  76. {
  77.     struct exception xcpt;
  78.     extern double log ();
  79.     extern double sqrt ();
  80.  
  81.     DBUG_ENTER (funcname);
  82.     DBUG_3 ("acoshin", "arg %le", x);
  83.     if (x < 1.0) {
  84.         xcpt.type = DOMAIN;
  85.         xcpt.name = funcname;
  86.         xcpt.arg1 = x;
  87.         if (!matherr (&xcpt)) {
  88.             fprintf (stderr, "%s: DOMAIN error\n", funcname);
  89.             errno = ERANGE;
  90.             xcpt.retval = 0.0;
  91.         }
  92.     } else if (x > SQRT_MAXDOUBLE) {
  93.         xcpt.type = OVERFLOW;
  94.         xcpt.name = funcname;
  95.         xcpt.arg1 = x;
  96.         if (!matherr (&xcpt)) {
  97.             fprintf (stderr, "%s: OVERFLOW error\n", funcname);
  98.             errno = ERANGE;
  99.             x = SQRT_MAXDOUBLE;
  100.             xcpt.retval = log (2* SQRT_MAXDOUBLE);
  101.         }
  102.     } else {
  103.         xcpt.retval = log (x + sqrt (x*x - 1.0));
  104.     }
  105.     DBUG_3 ("acoshout", "result %le", xcpt.retval);
  106.     DBUG_RETURN (xcpt.retval);
  107. }
  108.  
  109.